package com.cyan.learn.pattern.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 容器
 */
public class Composite implements Count {
    private List<Count> list = new ArrayList<>();

    public void add(Count count) {
        list.add(count);
    }

    public void delete(Count count) {
        list.remove(count);
    }

    @Override
    public int count() {
        int sum = 0;
        for (Count count : list) {
            sum = sum + count.count();
        }
        System.out.println("容器：" + sum);
        return sum;
    }
}
